<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
// import Edit from "./../edit/index";
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {},
  data() {
    return {
      appWindow: window,
      form: {
        // 聚合供应链-key
        app_key: "",
        // 聚合供应链--app_secret
        app_secret: "",
        // 回调地址
        callback_url: "",
        // 是否自动更新商品售价 0否 1是
        is_auto_sale_price: 1,
        // 是否自动更新商品成本价 0否 1是
        is_auto_original_price: 1,
        // 是否自动更新商品基本信息 0否 1是
        is_auto_product: 1,
        // 是否自动更新商品主图 0否 1是
        is_auto_product_pic: 1,
        // 是否去掉水印 0否 1是
        is_watermark: 1,
        // 是否创建品牌 0否 1是
        is_auto_brand: 1,
        // 是否使用供应链中台定价 0否 1是
        is_use_stbz_price: 1,
        // 价格策略
        price_strategy: [{
          // 来源1云仓2京东6阿里巴巴7天猫
          source: 1,
          // 1销售价 2成本价
          priceType: 1,
          // 1协议价 2指导价 3营销价
          policyType: 1,
          // 比率
          policyRatio: 90,
        }],
        // 风控策略 1价格策略 2利润率策略
        risk_strategy: 1,
        // 利润率百分比
        risk_ratio: "",
        // 1使用供应链运费 2商品自设运费
        freight_type: 1,
      },

      load: true,
      text: "",
    };
  },
  methods: {
    setText(source) {
      if(source == 1) {
        return "云仓";
      }else if(source == 2) {
        return "京东";
      }else if(source == 6) {
        return "阿里";
      }else if(source == 7) {
        return "天猫";
      }
    },
    async getData() {
      let res = await this.$vFN.Http.post({
        url: "plugin/supply/setting/edit",
      },window);
      this.form = res.data
      if(this.form.price_strategy == [] || this.form.price_strategy.length == 0) {
        this.form.price_strategy = [
          {source: 1, priceType: 1, policyType: 1, policyRatio: ""},
          {source: 1, priceType: 2, policyType: 3, policyRatio: ""},
          {source: 2, priceType: 1, policyType: 1, policyRatio: ""},
          {source: 2, priceType: 2, policyType: 3, policyRatio: ""},
          {source: 6, priceType: 1, policyType: 1, policyRatio: ""},
          {source: 6, priceType: 2, policyType: 3, policyRatio: ""},
          {source: 7, priceType: 1, policyType: 1, policyRatio: ""},
          {source: 7, priceType: 2, policyType: 3, policyRatio: ""},
        ]
      }
      
      if (res.code == 200) {
        this.load = false;
      }

    },

    async sum() {
      this.load = true;
      let res = await this.$vFN.Http.post({
        url: "plugin/supply/setting/store",
        data: this.form
      },window);
      if(res.code == 200) {
        this.$vFN.Tools.messageSuccess("操作成功");
        this.getData()
      }
    },

    // 初始化
    async init() {
      this.getData();
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>